//
//  SlideView.m
//  WWXELuShang
//
//  Created by lanou on 15/12/23.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "SlideView.h"

@implementation SlideView

- (instancetype)initWithFrame:(CGRect)frame target:(id)target {
    self = [super initWithFrame:frame];
    if (self) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kWidth / 12 )];
        view.backgroundColor = [UIColor grayColor];
        [self addSubview:view];
        [view addSubview:self.cancelButton];
        [view addSubview:self.sureButton];
        
        [self addSubview:self.hourPickerView];
        [self addSubview:self.minutePickerView];
        self.hourPickerView.delegate = target;
        self.minutePickerView.delegate = target;
        
        self.hourPickerView.dataSource = target;
        self.minutePickerView.dataSource = target;
        
        UILabel *hourLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth * 0.3 , self.frame.size.height / 2 - kWidth / 40, kWidth / 10 , kWidth / 20)];
        hourLabel.text = @"小时";
        hourLabel.font = [UIFont systemFontOfSize:kWidth / 22];
        UILabel *minLabel = [[UILabel alloc] initWithFrame:CGRectMake(kWidth * 0.7 , self.frame.size.height / 2 - kWidth / 40, kWidth / 10 , kWidth / 20)];
        minLabel.text = @"分钟";
        minLabel.font = [UIFont systemFontOfSize:kWidth / 22];
        [self addSubview:hourLabel];
        [self addSubview:minLabel];
        
        self.backgroundColor = [UIColor groupTableViewBackgroundColor];
        self.isHidden = YES;
        
    }
    return self;
}

//取消按钮
- (UIButton *)cancelButton {
    if (!_cancelButton) {
        _cancelButton = [[UIButton alloc]init];
        _cancelButton.frame = CGRectMake(kWidth / 40, 0, kWidth / 10, kWidth / 15);
        _cancelButton.titleLabel.font = [UIFont systemFontOfSize:kWidth / 20];
        [_cancelButton setTitle:@"取消" forState:(UIControlStateNormal)];
        
    }
    return _cancelButton;
}

//确定按钮
- (UIButton *)sureButton {
    if (!_sureButton) {
        _sureButton = [[UIButton alloc]init];
        _sureButton.frame = CGRectMake(kWidth - kWidth / 20 * 3, 0, kWidth / 10, kWidth / 15);
        _sureButton.titleLabel.font = [UIFont systemFontOfSize:kWidth / 20];
        [_sureButton setTitle:@"确定" forState:(UIControlStateNormal)];
        [_sureButton setTitleColor:[UIColor orangeColor] forState:(UIControlStateNormal)];
        _sureButton.tag = 1000;
        
    }
    return _sureButton;
}

//小时的选择
- (UIPickerView *)hourPickerView {
    if (!_hourPickerView) {
        _hourPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(kWidth * 0.1, self.frame.size.height / 4, kWidth / 5, self.frame.size.height / 2)];
    }
    return _hourPickerView;
}

//分钟的选择
- (UIPickerView *)minutePickerView {
    if (!_minutePickerView) {
        _minutePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(kWidth / 2, self.frame.size.height / 4, kWidth / 5, self.frame.size.height / 2)];
    }
    return _minutePickerView;
}


- (void)changeSlideView {
    CGFloat changeY;
    if (self.isHidden) {
        changeY = - kHeight / 5 * 2;
        self.isHidden = NO;
    }else {
        changeY = kHeight / 5 * 2;
        self.isHidden = YES;
    }
    
    //动画效果
    [UIView animateWithDuration:0.5 animations:^{
        self.transform = CGAffineTransformTranslate(self.transform, 0, changeY);
    }];
    
//    self.isHidden = !_isHidden;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
